<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/widgets/qvalidator.cpp -->
<head>
  <title>Qt 4.3: QRegExpValidator Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QRegExpValidator Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QRegExpValidator class is used to check a string against a regular expression. <a href="#details">More...</a></p>
<pre> #include &lt;QRegExpValidator&gt;</pre><p>Inherits <a href="qvalidator.html">QValidator</a>.</p>
<ul>
<li><a href="qregexpvalidator-members.html">List of all members, including inherited members</a></li>
<li><a href="qregexpvalidator-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<ul>
<li><div class="fn"/><b><a href="qregexpvalidator.html#regExp-prop">regExp</a></b> : QRegExp</li>
</ul>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qregexpvalidator.html#QRegExpValidator">QRegExpValidator</a></b> ( QObject * <i>parent</i> )</li>
<li><div class="fn"/><b><a href="qregexpvalidator.html#QRegExpValidator-2">QRegExpValidator</a></b> ( const QRegExp &amp; <i>rx</i>, QObject * <i>parent</i> )</li>
<li><div class="fn"/><b><a href="qregexpvalidator.html#dtor.QRegExpValidator">~QRegExpValidator</a></b> ()</li>
<li><div class="fn"/>const QRegExp &amp; <b><a href="qregexpvalidator.html#regExp-prop">regExp</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qregexpvalidator.html#regExp-prop">setRegExp</a></b> ( const QRegExp &amp; <i>rx</i> )</li>
<li><div class="fn"/>virtual QValidator::State <b><a href="qregexpvalidator.html#validate">validate</a></b> ( QString &amp; <i>input</i>, int &amp; <i>pos</i> ) const</li>
</ul>
<ul>
<li><div class="fn"/>4 public functions inherited from <a href="qvalidator.html#public-functions">QValidator</a></li>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QRegExpValidator class is used to check a string against a regular expression.</p>
<p>QRegExpValidator uses a regular expression (regexp) to determine whether an input string is <a href="qvalidator.html#State-enum">Acceptable</a>, <a href="qvalidator.html#State-enum">Intermediate</a>, or <a href="qvalidator.html#State-enum">Invalid</a>. The regexp can either be supplied when the QRegExpValidator is constructed, or at a later time.</p>
<p>When QRegExpValidator determines whether a string is <a href="qvalidator.html#State-enum">Acceptable</a> or not, the regexp is treated as if it begins with the start of string assertion (<b>^</b>) and ends with the end of string assertion (<b>$</b>); the match is against the entire input string, or from the given position if a start position greater than zero is given.</p>
<p>If a string is a prefix of an <a href="qvalidator.html#State-enum">Acceptable</a> string, it is considered <a href="qvalidator.html#State-enum">Intermediate</a>. For example, &quot;&quot; and &quot;A&quot; are <a href="qvalidator.html#State-enum">Intermediate</a> for the regexp <b>[A-Z][0-9]</b> (whereas &quot;_&quot; would be <a href="qvalidator.html#State-enum">Invalid</a>).</p>
<p>For a brief introduction to Qt's regexp engine, see <a href="qregexp.html">QRegExp</a>.</p>
<p>Example of use:</p>
<pre><span class="comment"> //</span> regexp: optional '-' followed by between 1 and 3 digits
 QRegExp rx(&quot;-?\\d{1,3}&quot;);
 QValidator *validator = new QRegExpValidator(rx, this);

 QLineEdit *edit = new QLineEdit(this);
 edit-&gt;setValidator(validator);</pre>
<p>Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.</p>
<pre><span class="comment"> //</span> integers 1 to 9999
 QRegExp rx(&quot;[1-9]\\d{0,3}&quot;);
<span class="comment"> //</span> the validator treats the regexp as &quot;^[1-9]\\d{0,3}$&quot;
 QRegExpValidator v(rx, 0);
 QString s;
 int pos = 0;

 s = &quot;0&quot;;     v.validate(s, pos);    <span class="comment">//</span> returns Invalid
 s = &quot;12345&quot;; v.validate(s, pos);    <span class="comment">//</span> returns Invalid
 s = &quot;1&quot;;     v.validate(s, pos);    <span class="comment">//</span> returns Acceptable

 rx.setPattern(&quot;\\S+&quot;);            <span class="comment">//</span> one or more non-whitespace characters
 v.setRegExp(rx);
 s = &quot;myfile.txt&quot;;  v.validate(s, pos); <span class="comment">//</span> Returns Acceptable
 s = &quot;my file.txt&quot;; v.validate(s, pos); <span class="comment">//</span> Returns Invalid

<span class="comment"> //</span> A, B or C followed by exactly five digits followed by W, X, Y or Z
 rx.setPattern(&quot;[A-C]\\d{5}[W-Z]&quot;);
 v.setRegExp(rx);
 s = &quot;a12345Z&quot;; v.validate(s, pos);        <span class="comment">//</span> Returns Invalid
 s = &quot;A12345Z&quot;; v.validate(s, pos);        <span class="comment">//</span> Returns Acceptable
 s = &quot;B12&quot;;     v.validate(s, pos);        <span class="comment">//</span> Returns Intermediate

<span class="comment"> //</span> match most 'readme' files
 rx.setPattern(&quot;read\\S?me(\.(txt|asc|1st))?&quot;);
 rx.setCaseSensitive(false);
 v.setRegExp(rx);
 s = &quot;readme&quot;;      v.validate(s, pos); <span class="comment">//</span> Returns Acceptable
 s = &quot;README.1ST&quot;;  v.validate(s, pos); <span class="comment">//</span> Returns Acceptable
 s = &quot;read me.txt&quot;; v.validate(s, pos); <span class="comment">//</span> Returns Invalid
 s = &quot;readm&quot;;       v.validate(s, pos); <span class="comment">//</span> Returns Intermediate</pre>
<p>See also <a href="qregexp.html">QRegExp</a>, <a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, and <a href="tools-settingseditor.html">Settings Editor Example</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="regExp-prop"></a>regExp : <a href="qregexp.html">QRegExp</a></h3>
<p>This property holds the regular expression used for validation.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>const QRegExp &amp; regExp () const</b></li>
<li><div class="fn"/><b>void setRegExp ( const QRegExp &amp; <i>rx</i> )</b></li>
</ul>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QRegExpValidator"></a>QRegExpValidator::QRegExpValidator ( <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
<p>Constructs a validator with a <i>parent</i> object that accepts any string (including an empty one) as valid.</p>
<h3 class="fn"><a name="QRegExpValidator-2"></a>QRegExpValidator::QRegExpValidator ( const <a href="qregexp.html">QRegExp</a> &amp; <i>rx</i>, <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
<p>Constructs a validator with a <i>parent</i> object that accepts all strings that match the regular expression <i>rx</i>.</p>
<p>The match is made against the entire string; e.g&#x2e; if the regexp is <b>[A-Fa-f0-9]+</b> it will be treated as <b>^[A-Fa-f0-9]+$</b>.</p>
<h3 class="fn"><a name="dtor.QRegExpValidator"></a>QRegExpValidator::~QRegExpValidator ()</h3>
<p>Destroys the validator.</p>
<h3 class="fn"><a name="validate"></a><a href="qvalidator.html#State-enum">QValidator::State</a> QRegExpValidator::validate ( <a href="qstring.html">QString</a> &amp; <i>input</i>, int &amp; <i>pos</i> ) const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Returns <a href="qvalidator.html#State-enum">Acceptable</a> if <i>input</i> is matched by the regular expression for this validator, <a href="qvalidator.html#State-enum">Intermediate</a> if it has matched partially (i.e&#x2e; could be a valid match if additional valid characters are added), and <a href="qvalidator.html#State-enum">Invalid</a> if <i>input</i> is not matched.</p>
<p>The <i>pos</i> parameter is set to the length of the <i>input</i> parameter.</p>
<p>For example, if the regular expression is <b>\w\d\d</b> (word-character, digit, digit) then &quot;A57&quot; is <a href="qvalidator.html#State-enum">Acceptable</a>, &quot;E5&quot; is <a href="qvalidator.html#State-enum">Intermediate</a>, and &quot;+9&quot; is <a href="qvalidator.html#State-enum">Invalid</a>.</p>
<p>Reimplemented from <a href="qvalidator.html#validate">QValidator</a>.</p>
<p>See also <a href="qregexp.html#exactMatch">QRegExp::exactMatch</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
